<template>
  <!-- 施组方案审批管理_审批 -->
  <div class="wrapper">
    <div class="title">施组方案审批管理_审批</div>
    <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
      <template>
        <title-name title="节点信息" />
        <a-descriptions class="mb20" title="">
          <a-descriptions-item label="当前节点">
            {{ taskName }}
          </a-descriptions-item>
          <a-descriptions-item label="审批人">
            {{ currentUser.name }}
          </a-descriptions-item>
          <a-descriptions-item label="审批时间">
            {{ currentTime }}
          </a-descriptions-item>
        </a-descriptions>
      </template>
      <div v-if="bcRporateAuditor && businessTypeCode!='809'">
        <title-name title="施组(方案)打分表" />
        <div class="title">
          否决项
        </div>
        <a-table :columns="columns" :data-source="tableDataFj" bordered :pagination="false">
          <!-- CheckBox选择框 -->
          <template slot="checkbox" slot-scope="text, record">
            <a-checkbox @change="changeCheckbox(record)" />
          </template>
          <!-- 序号 -->
          <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
        </a-table>
        <div class="title">
          评分项
        </div>
        <a-table :columns="columnsScore" :data-source="ScoreTableData" bordered :pagination="false">
          <!-- 序号 -->
          <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
          <template slot="score" slot-scope="text, record">
            <!-- <a @click="editScore(record)">评分</a> -->
            <BaseInputNumber
              v-model="record.score"
              style="width: 100px"
              :max="getMaxValue(record)"
              :precision="1"
              :min="0"
              placeholder="请评分"
              @blur="changeScore()"
            />
          </template>
          <template slot="information" slot-scope="text, record">
            <!-- <a @click="editScore(record)">评分</a> -->
            <BaseInput v-model="record.information" placeholder="请输入评分说明" type="textarea" />
          </template>
        </a-table>
        <div class="title">
          审核结果
        </div>
        <a-form-model
          :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
          :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
        >
          <a-row>
            <a-col :md="8" :sm="8">
              <a-form-model-item label="审核总分">
                <BaseInput v-model="totalScore" disabled />
              </a-form-model-item>
            </a-col>
            <a-col :md="8" :sm="8">
              <a-form-model-item label="审核结果">
                <BaseInput v-model="result" disabled />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
      <a-form-model ref="ruleForm" :model="form" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }" :rules="rules">
        <!-- 表格 -->
        <title-name title="其他信息" />
        <a-row :gutter="24">
          <a-col :md="24" :sm="24" v-if="corporateAuditor">
            <a-form-model-item label="星级" prop="starLevel">
              <a-rate v-model="form.starLevel" style="color: #1890ff; font-size: 30px" />
            </a-form-model-item>
          </a-col>
          <a-col :md="24" :sm="24">
            <a-form-model-item label="修改意见">
              <a-table ref="formTable" bordered :columns="columns1" :data-source="form.tableData" :pagination="false">
                <template v-for="col in ['opinion']" :slot="col" slot-scope="text, record">
                  <div :key="col" class="form-item">
                    <template> <BaseInput v-if="col === 'opinion'" v-model="record[col]"></BaseInput> </template></div
                ></template>
                <template slot="action" slot-scope="text, record, index">
                  <span>
                    <a-popconfirm title="确定要删除?" @confirm="() => del(1, index)">
                      <a>删除</a>
                    </a-popconfirm>
                  </span>
                </template>
                <template slot="footer">
                  <a-button type="primary" @click="addLine(1)">增行</a-button>
                </template>
              </a-table>
            </a-form-model-item>
          </a-col>
          <a-col :md="24" :sm="24">
            <a-form-model-item label="建议意见">
              <a-table ref="formTable" bordered :columns="columns2" :data-source="form.tableData2" :pagination="false">
                <template v-for="col in ['opinion']" :slot="col" slot-scope="text, record">
                  <div :key="col" class="form-item">
                    <template> <BaseInput v-if="col === 'opinion'" v-model="record[col]"></BaseInput> </template></div
                ></template>
                <template slot="action" slot-scope="text, record, index">
                  <span>
                    <a-popconfirm title="确定要删除?" @confirm="() => del(2, index)">
                      <a>删除</a>
                    </a-popconfirm>
                  </span>
                </template>
                <template slot="footer">
                  <a-button type="primary" @click="addLine(2)">增行</a-button>
                </template>
              </a-table>
            </a-form-model-item>
          </a-col>
        </a-row>
        <Consultation
          :proc-inst-id="procInstId"
          :is-show-btn="$route.query.isMonitoring ? ($route.query.monitoringType === 'process' ? true : false) : true"
          :task-name="taskName"
          :sub-approver-list.sync="subApproverList"
        >
          <template slot="approverButton">
            <template v-if="bcRporateAuditor && businessTypeCode!='809'">
              <a-button type="primary" v-if="totalScore < 60 || vetoList.length>0" :loading="loading.REJECT" @click="handleSave('REJECT')">提交审核结果</a-button>
              <a-button type="primary" v-else :loading="loading.PASS" @click="handleSave('PASS')">提交审核结果</a-button>
            </template>
            <template v-else>
              <a-button type="primary" :loading="loading.REJECT" @click="handleSave('REJECT')">审批不通过</a-button>
              <a-button type="primary"  :loading="loading.PASS" @click="handleSave('PASS')">审批通过</a-button>
            </template>
          </template>
        </Consultation>
      </a-form-model>
      <template>
        <title-name title="审批流程信息" />
        <div class="btns-wrapp mb20">
          <a-button type="primary" @click="visibleState.auditProcess = true"> 审批流程图 </a-button>
        </div>
        <a-spin tip="流程信息加载中..." :spinning="flowRequesting" />
        <a-table :columns="columnApprove" :data-source="approveInfos" bordered>
          <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
          <!-- <template slot="opinions" slot-scope="text, record">
            <a-tooltip placement="topLeft">
              <template slot="title">
                <p> {{ record.formData.opinions }}</p>
                <p> {{ record.formData.opinions2 }}</p>
              </template>
              <p> {{ record.formData.opinions }}</p>
              <p> {{ record.formData.opinions2 }}</p>
            </a-tooltip>
          </template> -->
        </a-table>
      </template>
      <title-name title="回复信息" />
      <a-table ref="formTable" bordered :columns="replyMessageColumns" :data-source="opinionVOS" :pagination="false">
        <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
      </a-table>
    </a-card>
    <ApprovalDetails :title="'审批流程信息'" :business-id="id" :visible="visibleState.auditProcess" @cancel="visibleState.auditProcess = false" @confirm="visibleState.auditProcess = false" />
    <AuditBusinessDetail />
  </div>
</template>

<script>
import moment from 'moment'
import Vue from 'vue'
import { notifyParentWindow } from '@/utils/util.js'
import riskListApi from '@/api/legal/risk/list'
import SelectPersonModal from '@/components/SelectPersonModal' // 人员
import { Rate } from 'ant-design-vue'
import ApprovalDetails from '@/components/approvalDetails'
import { getProcessNodeList, completeTask } from '@/api/process'
import { createAuditApproval, getAuditApproval, getDetails } from '@/api/technical/approval'
import { getOrgEmployeesListBy,} from '@/api/commons'
import Consultation from '@/views/matters/approval/components/consultation'
import AuditBusinessDetail from '@/views/matters/AuditBusinessDetail'
import { submitConstructionScoreForm } from '@/api/design/designManage'
import Template from '@/views/construction/gantt/template.vue'
const columns1 = [
  { title: '修改意见内容', dataIndex: 'opinion', align: 'center', scopedSlots: { customRender: 'opinion' } },
  { title: '操作', dataIndex: 'action', width: '120px', align: 'center', scopedSlots: { customRender: 'action' } }
]
const columns2 = [
  { title: '建议意见内容', dataIndex: 'opinion', align: 'center', scopedSlots: { customRender: 'opinion' } },
  { title: '操作', dataIndex: 'action', width: '120px', align: 'center', scopedSlots: { customRender: 'action' } }
]

const columnApprove = [
  { title: '序号', width: 80, align: 'center', scopedSlots: { customRender: 'serial' } },
  { title: '审批人', dataIndex: 'userName', ellipsis: true, width: 180 },
  { title: '审批时间', dataIndex: 'endTime', ellipsis: true, width: 180 },
  { title: '节点名称', dataIndex: 'taskName', ellipsis: true, width: 180 },
  { title: '滞留时间', dataIndex: 'durationInMillis', ellipsis: true, width: 140 },
  { title: '审批意见', dataIndex: 'formData.opinions', scopedSlots: { customRender: 'opinions' }, ellipsis: true }
]
const replyMessageColumns = [
  { title: '序号', width: 80, align: 'center', scopedSlots: { customRender: 'serial' } },
  { title: '修改意见', dataIndex: 'opinion', ellipsis: true },
  { title: '回复信息', dataIndex: 'opinionReply', ellipsis: true }
]
export default {
  name: 'auditorApproval',
  components: {
    SelectPersonModal,
    ARate: Rate,
    ApprovalDetails,
    Consultation,
    AuditBusinessDetail,
    Template
  },
  data() {
    return {
      columns1,
      columns2,
      columnApprove,
      replyMessageColumns,
      form: {
        starLevel: null,
        tableData: [
          {
            opinion: null
          }
        ],
        tableData2: [
          {
            opinion: null
          }
        ]
      },
      formName: '', // 添加人员绑定字段
      formInfo: {}, // 风险基础信息
      visible: false,
      rules: {
        starLevel: [{ required: true, message: '请选择', trigger: 'change' }]
      }, // 校验规则
      loading: false,
      loadingBtn: {
        DELETE: false,
        DRAFT: false,
        SUBMITTED: false,
        REJECTED: false
      },
      opinions: '',
      approveInfos: [], // 审批流程信息
      procInstId: '', //当前流程实例ID
      taskId: '', //当前流程节点ID
      processName: '', //流程名称
      taskName: '', //当前流程节点名称
      taskDefKey: '', //任务标识
      currentTime: '', //当前审批时间
      currentUser: '', //当前审批人
      flowRequesting: false,
      detailUrl: null, //详情地址
      spinning: false,
      assignType: '', //节点类型   0 变量获取 1 处理人 2 候选人 3 候选组 4 会签
      assignCode: '', //候选组编码 岗位编码
      assignLevel: '', //层级 项目部 PD 分公司 BC 公司 CO
      businessType: '', //业务类型 0 项目
      args: {}, // 添加人员请求参数
      visibleState: {
        auditProcess: false
      },
      // 下级审批人
      subApproverList: [],
      versionNumber:null,
      auditApprovalData:[],
      opinionVOS:[], //回复信息
      tableDataFj: [], //否决table
      totalScore: 100,
      result: '优秀',
      vetoHeaderId: '',
      ScoreTableData: [],
      columns:[],
      columnsScore:[],
      vetoList:[],
      scoreInformation: '',
      scorecount:'',
      businessTypeCode:null,
    }
  },
 async created() {
    const { type, code, level, btype, businessId, procInstId, name, processName, detailUrl, taskId, taskDefKey,businessType} = this.$route.query
    if (type) {
      this.assignType = type
      this.assignCode = code
      this.assignLevel = level
      this.businessType = btype
      this.businessTypeCode = businessType
    }
    this.id = businessId
    if (!this.id) {
      this.$error({ content: '无指定业务ID，将自动关闭' })
      setTimeout(() => {
        window.close()
      }, 1500)
      return
    }
    this.procInstId = procInstId
    this.taskName = decodeURIComponent(name)
    this.processName = decodeURIComponent(processName)
    document.title = this.processName + '-' + this.taskName
    if (detailUrl) {
      this.detailUrl = decodeURIComponent(detailUrl)
    }
    this.taskId = taskId
    this.taskDefKey = taskDefKey
    this.currentTime = moment().format('YYYY-MM-DD')
    this.currentUser = Vue.getAcloudProvider().getUserInfo()
    this.getProcessNodes()
    if(this.id){
       await this.getDetails();
    }
  },
  computed:{
    //是否是分公司和公司方案审核师
    corporateAuditor(){
      return this.taskDefKey == 'BC_FASHS_AUDIT' || this.taskDefKey == 'CO_FASHS_AUDIT'
    },
    //是否是分公司
     bcRporateAuditor(){
      return this.taskDefKey == 'BC_FASHS_AUDIT';
    },
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
        selectedRows: this.selectedRows, // 当前行所有数据
        onChange: this.onSelectChange
      }
    }
  },
  methods: {
    isEmpty(obj) {
      if ((typeof obj == 'undefined' || obj == null || obj == '') && obj !== 0) {
        return true
      } else {
        return false
      }
    },
    /**
     * 提交表单
     */
    validateForm(status) {
      let flag = false
      let form = this.form
      if (status == 'REJECT') {
        if (!form.tableData.length) {
          this.$message.warning('请完善修改意见表格数据')
        } else {
          let rulesArr = []
          form.tableData.map((item) => {
            let a = Object.values(item).every((oItem) => !this.isEmpty(oItem))
            a && rulesArr.push(a)
          })
          flag = rulesArr.length === form.tableData.length
          if (!flag) {
            this.$message.warning('请完善修改意见表格数据')
            return
          }
        }
      } else {
         if(this.corporateAuditor && !form.starLevel){   //分公司审批通过必须填写星级
          this.$message.warning('请填写星级')
          return
         }
        if (!form.tableData.length && !form.tableData2.length) {
          this.$message.warning('请填写修改意见或建议意见')
        } else {
          let rulesArr = [],
            rulesArr2 = []
          form.tableData.map((item) => {
            let a = Object.values(item).every((oItem) => !this.isEmpty(oItem)) //所有行都要填写完成
            a && rulesArr.push(a)
          })
          let flag1 = false
          if (form.tableData.length && rulesArr.length === form.tableData.length) {
            flag1 = true
          }
          form.tableData2.map((item) => {
            let b = Object.values(item).every((oItem) => !this.isEmpty(oItem)) //所有行都要填写完成
            b && rulesArr2.push(b)
          })
          let flag2 = false
          if (form.tableData2.length && rulesArr2.length === form.tableData2.length) {
            //所有行都要填写完成
            flag2 = true
          }

          if (!flag1 && !flag2) {
            flag = false
            this.$message.warning('请填写修改意见或建议意见')
            return
          } else {
            flag = true
          }
        }
      }
      return flag
    },
    // 处理增、删、改操作
    async handleSave(status) {
      if (this.loadingBtn[status]) return
      if (!this.validateForm(status)) {
        return
      }
      if (status == 'PASS') {
        //通过
        this.handelApproval(status)
      } else {
        this.handelUnApproval(status)
      }
    },
    /**
     * @description: 组装下级审批人数据
     * @param {array} subApproverList 下级审批人表格数据
     * @return {object} 下级审批人数据
     */
    createApproverList(subApproverList) {
      const subordinateApproverList = {}
      subApproverList.forEach((item) => {
        if (item?.approver && item.approver.length > 0) {
          subordinateApproverList[item.taskInfo.id] = {
            assgins: item.approver?.map((el) => el.key).join(','),
            assignTypeEnum: 2
          }
        }
      })
      return subordinateApproverList
    },
    handelUnApproval() {
      // 审批不通过
      const _this = this
      // if (!_this.opinions) {
      //   _this.$warning({ content: '请填写审批意见' })
      //   return
      // }
      const confirmWin = this.$confirm({
        title: '警告提醒！',
        content: '确定审批不通过？',
        okType: 'danger',
        onOk() {
          return new Promise((resolve, reject) => {
            if(!_this.bcRporateAuditor || _this.businessTypeCode=='809'){  
              _this
              .submit(true)
              .then(() => {
                resolve()
                confirmWin.destroy()
              })
            }else{
              _this.submitScoreForm().then((res)=>{
              if(res){
                _this
              .submit(true)
              .then(() => {
                resolve()
                confirmWin.destroy()
              })
              .catch(() => reject)
              }

            })
            }


          }).catch(() => this.$error({ content: '审批提交失败，请稍后重试' }))
        },
        onCancel() {}
      })
    },

    handelApproval() {
      // 审批通过
      const _this = this
      const confirmWin = this.$confirm({
        title: '警告提醒！',
        content: '确定审批通过？',
        okType: 'danger',
        onOk() {
          return new Promise((resolve, reject) => {
            if(!_this.bcRporateAuditor || _this.businessTypeCode=='809'){ 
              _this.submit(false, _this.createApproverList(_this.subApproverList))
              .then(() => {
                _this.handleGetPostsChangeLog() //获取一周内岗位变更数量
                notifyParentWindow() // 通知父窗口
                resolve()
                confirmWin.destroy()
              })
              .catch(() => reject)
             }
             else{
              _this.submitScoreForm().then((res)=>{
              if(res){
               _this.submit(false, _this.createApproverList(_this.subApproverList))
              .then(() => {
                _this.handleGetPostsChangeLog() //获取一周内岗位变更数量
                notifyParentWindow() // 通知父窗口
                resolve()
                confirmWin.destroy()
              })
              .catch(() => reject)
              }

            })
             }
      
          }).catch((err) => {
            console.log(err)
            this.$error({ content: '审批提交失败，请稍后重试' })
          })
        },
        onCancel() {}
      })
    },
    //添加行
    addLine(data) {
      if (data == 1) {
        this.form.tableData.push({ opinion: null })
      } else {
        this.form.tableData2.push({ opinion: null })
      }
    },
    //删除行
    del(data, idx) {
      if (data == 1) {
        this.form.tableData.splice(idx, 1)
      } else {
        this.form.tableData2.splice(idx, 1)
      }
    },
    //获取审批信息
    getProcessNodes() {
      this.flowRequesting = true
      getProcessNodeList({ procInstId: this.procInstId, pageNo: 1, pageSize: 100 })
        .then((res) => {
          if (res.code === 200) {
            const data = res.data
            const userIds = data.map((d) => {
              if (d.formData) {
                d.formData = JSON.parse(d.formData)
              }
              return d.assignee
            })
            getOrgEmployeesListBy({ userIds, delete: true }).then((employees) => {
              this.flowRequesting = false
              res.data.forEach((r) => {
                employees.data.some((e) => {
                  if (e.userId === r.assignee) {
                    r.userName = e.name
                    return true
                  }
                })
              })
              this.approveInfos = res.data
            })
          }
        })
        .catch(() => {
          this.flowRequesting = false
        })
    },
    /**
     * @description: 完成审批
     * @param {*} reject 是否拒绝
     * @return {*}
     */
    submit(reject) {
      let tableData1 = this.form.tableData,
       tableData2 = this.form.tableData2,
       tableData3=[],
       tableData4=[],
       str1 = '',
       str2='';
       if(tableData1.length){
        tableData1.map((item,index)=>{
          if(item.opinion && item.opinion!=''){
            tableData3.push(
            `${index+1}、${item.opinion}`
          ) 
          }
        })
       }
       if(tableData2.length){
        tableData2.map((item,index)=>{
           if(item.opinion && item.opinion!=''){
              tableData4.push(
              `${index+1}、${item.opinion}`
            ) 
           }
        })
       }
       str1 = tableData3.join(';');
       str2 = tableData4.join(';');
       let str3 = '',
       str4 = '';
       if(str1!=''){
        str3 = `修改意见：${str1}`
       }else{
        str3=''
       }
       if(str2!=''){
        str4 = `建议意见${str2}`
       }else{
        str4=''
       }
       this.opinions = `${str3}${str4}`
        //流程确认接口,流程接口
        let pmsTableData1 = this.form.tableData,
          pmsTableData2 = this.form.tableData2,
            opinionDTOList = []
          if (pmsTableData1 && pmsTableData1.length) {
            pmsTableData1.map((item) => {
              item.type = '1'
              item.replyStatus = '0'
            })
          }
          if (pmsTableData2 && pmsTableData2.length) {
            pmsTableData2.map((item) => {
              item.type = '2'
              item.replyStatus = '0'
            })
          }
          opinionDTOList = [...pmsTableData1, ...pmsTableData2]
          let params = {
            programId: this.id,
            approvalUserName: this.currentUser.name,
            approvalUserId: this.currentUser.id,
            nodeName: this.taskName,
            nodeCode: this.taskDefKey,
            approvalDate: this.currentTime,
            opinionDTOList
          }
          if (this.corporateAuditor) {
            params.starLevel = this.form.starLevel
          }
          //业务流程处理
          return createAuditApproval(params).then((res) => {
              if (res.code == 200) {
                const data = {
                  formData: {
                    opinions: this.opinions,
                    reject,
                    projectId: ''
                  },
                  assignTypeEnum: this.assignType, //指派类型
                  assgins: this.form.respEmployeeId, //人员
                  groupEnum: this.form.jobsSelectedName, //岗位
                  procInstId: this.procInstId,
                  taskId: this.taskId,
                  userId: this.currentUser.id
                }
                const variable = {}
                // return;
                if (reject) {
                  variable.reject = true
                }

                data.variables = {
                  ...variable,
                  ...this.submitData // 特殊流程的数据，转交给审批
                }
                completeTask(data)
                .then((res) => {
                  if (res.status === 200) {
                    notifyParentWindow() // 通知父窗口
                        // this.$success({
                        //   content: '审批提交成功，即将自动关闭当前窗口',
                        //   onOk() {
                            window.close()
                        //   }
                        // })
                        // setTimeout(() => {
                        //   window.close()
                        // }, 2000)
              
                  } else {
                    this.$error({ content: '审批提交失败，请稍后重试' })
                  }
                  return res
                })
                .catch((err) => {
                  return err
                })
              }
            })
    },
    //获取详情
    getDetails() {
      if (this.id) {
        let api = getDetails
        api({ id: this.id }).then((res) => {
           this.versionNumber = res.data.versionNumber;
           this.getAuditApprovalFn( this.versionNumber)
           let previousVersionNumber = this.versionNumber*1 - 1;
           previousVersionNumber && this.getAuditPreviousApprovalFn(previousVersionNumber);

           this.form = {
            ...this.form,
            ...res.data
          }
          this.form.programTypeId = res.data.programTypeId
          this.form.planSelection = res.data.planSelectionId
          this.form.whetherMajorExpense = res.data.whetherMajorExpense === 'true' ? true : false
          this.form.whetherProfessionalSubcontracting =
            res.data.whetherProfessionalSubcontracting === 'true' ? true : false
          this.$nextTick(() => {
            this.form.projectId = res.data.projectId
          })
          this.initTable(res)
        })
      }
    },
    //查询当前施组的审批节点
     getAuditApprovalFn(versionNumber) {
      let parms = {
        versionNumber,
        programId:this.id,
      }
      getAuditApproval(parms).then((res)=>{
        if(res.code == 200){
          this.auditApprovalData = res.data;
          const userId = JSON.parse(sessionStorage.getItem('ycloud-user_info')).id
          this.auditApprovalData.forEach(item=>{
            if (item.nodeCode === this.taskDefKey && userId === item.approvalUserId){
              let opinionVOS = item.opinionVOS;
              this.opinionVOS = opinionVOS.filter((cItem)=>cItem.type*1===1);
            }
          })
          // if( this.approveInfos.length && this.auditApprovalData.length){   //用之前的，不会递归循环赋值
          //       this.approveInfos.map((item)=>{
          //         this.auditApprovalData.map((cItem)=>{
          //             if(item.taskDefKey==cItem.nodeCode){
          //               item.formData.opinions = `${cItem.modifications?cItem.modifications:''}`
          //               item.formData.opinions2 = `${cItem.suggestions?cItem.suggestions:''}`;
          //             }
          //           })
          //         })
          //     }
        }
      })
    },
    //查询上一节点施组的审批节点
    getAuditPreviousApprovalFn(previousVersionNumber){
      let parms = {
        versionNumber:previousVersionNumber,
        programId:this.id,
      }
      getAuditApproval(parms).then((res)=>{
        if(res.code == 200){
           let data = res.data || [];
           if(data.length){
            data.map((item)=>{
              if(item.approvalUserId == this.currentUser.id && item.nodeCode == this.taskDefKey){
                 let opinionVOS = item.opinionVOS;
                 this.opinionVOS = opinionVOS.filter((cItem)=>cItem.type*1===1);
              }
            })
           }
        }
      })
    },
    submitScoreForm() {
      if(!this.bcRporateAuditor || this.businessTypeCode=='809'){  
         return 
      }
      let arr = []
      this.ScoreTableData.forEach(item => {
        arr.push({
          id: item.id,

          scoreIns: item.information,
          scoreCont: item.score
        })
      })
      let newData = JSON.parse(JSON.stringify(arr).replace(/scoreIns/g, this.scoreInformation))
      let datas = JSON.parse(JSON.stringify(newData).replace(/scoreCont/g, this.scorecount))
      this.contentList = datas
      let submitForm = []
      submitForm.push({
        id: this.form.id,
        vetoList: this.vetoList,
        contentList: this.contentList,
        totalScore: this.totalScore,
        result: this.result,
        opinion:this.opinions 
      })
      return submitConstructionScoreForm(submitForm[0]).then(res => {
        if (res.code === 200) {
          return true;
          // console.log(this.totalScore < 60 || this.vetoList.length > 0)
          if (this.totalScore < 60 || this.vetoList.length > 0) {
            //this.submit(true)
          } else {
           // this.submit(false)
          }
        } else {
          return false;
          this.$error({ content: '提交失败，请稍后重试' })
        }
        // if (res.code == '200') {
        //     this.$message.success('提交审核成功')
        //     this.$router.push('/project/design/plotsManage')
        // }
      })
    },
  // 获取输入项的最大允许值
       getMaxValue(data) {
      const targetData = this.columnsScore.find(item => item.code === '4') // 考核评分列
      return (targetData && Number(data[targetData['dataIndex']])) || 0
    },
    onSelectChange(selectedRowKeys) {
      console.log('selectedRowKeys changed: ', selectedRowKeys)
      this.selectedRowKeys = selectedRowKeys
    },
    changeCheckbox(record) {
      let list = []
      let obj = []
      let arr = []

      record.check = !record.check
      arr = this.tableDataFj.filter(items => items.check == true)

      arr.forEach(item => {
        obj.push({
          id: item.id,
          ids: '是'
        })
      })
      let newdata = JSON.parse(JSON.stringify(obj).replace(/ids/g, this.vetoHeaderId))
      this.vetoList = newdata
      console.log(this.vetoList)
    },
    changeScore(value) {
      let arr = []
      let obj = 2
      this.ScoreTableData.forEach(item => {
        console.log(item.score)
        if (item.score) {
          arr.push(parseFloat(item.score))
        }
      })
      console.log(arr)
      console.log(obj)

      this.totalScore = arr.length > 0 ? (this.totalScore = 100 - eval(arr.join('+'))) : 100

      console.log(this.totalScore)
      if (this.totalScore < 70) {
        this.result = '不合格'
      } else if (this.totalScore >= 70 && this.totalScore < 80) {
        this.result = '合格'
      } else if (this.totalScore >= 80 && this.totalScore < 90) {
        this.result = '良好'
      } else if (this.totalScore >= 90) {
        this.result = '优秀'
      }
    },
    initTable(res) {
      // 否决项
      this.columns = res.data.vetoHeader
      this.tableDataFj = res.data.vetoContent
      this.columns.unshift({
        dataIndex: 'serial',
        formId: null,
        title: '序号',
        code: '0',
        sort: 0,
        inputType: null,
        scopedSlots: { customRender: 'serial' }
      })
      let obj = {}
      this.columns.forEach(item => {
        obj = this.columns.filter(items => items.code == '9')
      })
      console.log(obj)
      this.vetoHeaderId = obj[0].dataIndex
      obj[0].scopedSlots = { customRender: 'checkbox' }
      console.log(this.columns)

      this.columnsScore = res.data.scoreHeader
      this.ScoreTableData = res.data.scoreContent
      // this.formDatas = cloneDeep(res.data.scoreHeader)
      this.columnsScore.unshift({
        dataIndex: 'serial',
        formId: null,
        title: '序号',
        code: '0',
        sort: 0,
        inputType: null,
        scopedSlots: { customRender: 'serial' }
      })

      let objScore = {}
      this.columnsScore.forEach(item => {
        objScore = this.columnsScore.filter(items => items.code == '10')
      })
      objScore[0].scopedSlots = { customRender: 'score' }
      this.scorecount = objScore[0].dataIndex

      let information = {}
      this.columnsScore.forEach(item => {
        information = this.columnsScore.filter(items => items.code == '9')
      })
      information[0].scopedSlots = { customRender: 'information' }
      this.scoreInformation = information[0].dataIndex
    },
  }
}
</script>

<style lang="less" scoped>
.img-wrapper {
  padding: 10px 0;
}
.wrapper {
  padding: 20px;

  .title {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 20px;
  }

  /deep/ .approval-item .ant-form-item-control-wrapper {
    width: 100%;
  }
}

.wrapper-row {
  padding-left: 55px;
  font-weight: bold;
  letter-spacing: 1px;
}

/deep/ .ant-form-item label {
  font-size: 12px;
}

/deep/ .ant-btn {
  border-radius: 5px;
}

/deep/ .ant-input {
  /*width: 70%;*/
  border-radius: 5px;
}

/deep/ .ant-card.ant-card-bordered {
  border-radius: 5px;
}

.ant-avatar-lg {
  width: 48px;
  height: 48px;
  line-height: 48px;
}

.list-content-item {
  color: rgba(0, 0, 0, 0.45);
  display: inline-block;
  vertical-align: middle;
  font-size: 14px;
  margin-left: 40px;

  span {
    line-height: 20px;
  }

  p {
    margin-top: 4px;
    margin-bottom: 0;
    line-height: 22px;
  }
}

.title-name {
  border-left: 5px solid #1890ff;
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 20px;
  padding-left: 15px;
  height: 20px;
  line-height: 20px;
}

/deep/ .table-page-search-wrapper .ant-form-inline .ant-row .ant-col.ant-col-sm-24.ant-col-md-12 {
  padding-left: 80px;
}

/deep/ .col .ant-form-item .ant-form-item-control-wrapper {
  width: calc(100% - 135px);
}
/deep/ .BaseTextarea-container .ant-input {
  border-color: #e4ac0b;
  background-color: #fff9e8;
}
</style>

